require 'soap/header/simplehandler'

class AmazonFPS

  class HeaderHandler < SOAP::Header::SimpleHandler
    attr_reader :tag
    attr_writer :value

    def initialize(tag, value)
      super(XSD::QName.new(nil, tag))
      @tag = tag
      @value = value
    end

    def on_simple_outbound
      @value
    end
  end

  # Sets up the credentials for the AmazonFPS session
  class Credentials
    attr_reader :handlers
    
    # Load the credentials from the credentials Hash
    def initialize(credentials)
      @handlers = Array.new
      credentials.each_pair do |key, value|
        @handlers << HeaderHandler.new(key, value) 
      end
    end
    
    def setHeader(header, value)
      handlers.each do |handler|
        if handler.tag == header then
          handler.value = value
        end
      end
    end
    
  end
end